/**
 * @(#)OrderManagement.java 2011
 *
 *
 * Copyright 2011 classic-commerce
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package ca.ioniq.server.service;

import java.util.Date;
import java.util.List;

import ca.ioniq.server.service.exception.OrderException;
import ca.ioniq.server.service.impl.OrderManagementServiceImpl;
import ca.ioniq.shared.entity.Order;

import com.google.inject.ImplementedBy;

/**
 * @author: <a href="mailto:richard@ioniq.ca">Richard Mutezintare</a>
 */

@ImplementedBy(OrderManagementServiceImpl.class)
public interface OrderManagementService {

	/**
	 * View the list of orders from a given date till now. 
	 * If there is no order in this period a empty list is returned. 
	 * @param date the given date
	 * @return list of order placed after the given date
	 */
	List<Order> viewLastOrders(Date date);

	/**
	 * View the list of orders by company from a given date till now. 
	 * If there is no order in this period a empty list is returned. 
	 * @param date the given date
	 * @return list of order placed after the given date
	 */
	List<Order> viewLastOrdersByCompany(Date date, Long companyId);
	
	/**
	 * View all orders.
	 * If there is no order in this period a empty list is returned. 
	 * @return list of orders
	 */
	List<Order> viewAllOrders();

	/**
	 * View all orders for a company.
	 * If there is no order in this period a empty list is returned. 
	 * @return list of orders
	 */
	List<Order> viewAllOrdersByCompany(Long companyId);
	
	/**
	 * Get order by a given id.
	 * @param orderId order id
	 * @return the order with the given id
	 */
	Order viewOrder(long orderId) throws OrderException;
	
	/**
	 * Get orders for a given user.
	 * @param userId the given user
	 * @return list of orders
	 */
	List<Order> viewOrdersByUser(Long userId);
	
	/**
	 * Get orders for a given user.
	 * @param userId the given user
	 * @return list of orders
	 */
	List<Order> viewOrdersByUserAndCompany(Long userId, Long companyId);
	
	/**
	 * Set a order to cancel.
	 * @param orderId id for the order to be canceled
	 * @return true/false for the operation
	 */
	boolean cancelOrder(long orderId);
	
	/**
	 * Update a order. The old properties will be replaced with the new properties.
	 * @param order order to be updated
	 * @throws OrderException in case the update is not fine
	 */
	void updateOrder(Order order) throws OrderException;
	
	/**
	 * Update a order knowing the id. The old properties will be replaced with the new properties.
	 * @param order order to be updated
	 * @throws OrderException in case the update is not fine
	 */
	void updateOrder(Order order, long orderId) throws OrderException;

	/**
	 * Get a order from repository
	 * @param id the given order id
	 * @return the order
	 */
	Order getOrder(Long id);

	/**
	 * Put a order in repository
	 * @param order the given order
	 * @return the persisted order
	 */
	Order putOrder(Order order);

}
